package com.cyzy.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.cyzy.dao.UserRole;
import com.cyzy.mapper.CampusMapper;
import com.cyzy.mapper.SecKillMapper;
import com.cyzy.pojo.Contract;
import com.cyzy.pojo.Course;
import com.cyzy.pojo.Seckill;
import com.cyzy.pojo.SeckillJoin;
import com.cyzy.service.CampusService;
import org.checkerframework.checker.units.qual.A;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.xml.crypto.Data;
import java.sql.Timestamp;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.List;

@Service
public class CampusServiceImpl implements CampusService {

    @Autowired
    private CampusMapper campusMapper;

    @Autowired
    private SecKillMapper secKillMapper;

    @Override
    public Page<Contract> selectContractByUserId(Long userId, Long pageSize, Long pageNum,Double contractAmount,String paymentStatus,String startDate,
                                                 String endDate,String signTime) {
        Page<Contract> page = new Page<>(pageNum, pageSize);

        return campusMapper.selectContractByUserId(page ,userId, contractAmount, paymentStatus, startDate, endDate,signTime);

    }

    @Override
    public Page<SeckillJoin> getAllSecKill(Long userId, Long pageSize, Long pageNum) {
        Page<SeckillJoin> page = new Page<>(pageNum, pageSize);
        return campusMapper.getAllSecKill(page,userId);
    }

    @Override
    public int insertSecKill(Seckill seckill) {

        //获取开始时间，结束时间
        LocalDateTime localDateTime = seckill.getStartTime().toLocalDateTime();
        LocalDateTime localEndTime = localDateTime.plusHours(seckill.getSeckillTime());
        seckill.setEndTime(Timestamp.valueOf(localEndTime));
        seckill.setStatus("待审核");
        int i = secKillMapper.insert(seckill);
        System.out.println("插入的主键为:"+seckill.getSeckillId());
        return i;
    }

    @Override
    public String queryCampusNameWhenSecKill(Long campusId) {

        return campusMapper.selectById(campusId).getCampusName();
    }

    @Override
    public List<Course> queryAllCourseByCampusId(Long campusId,Integer type) {

        Course course = new Course();
        course.setCampusId(campusId);
        course.setCourseStatus(String.valueOf(type));
        System.out.println(course);
        return campusMapper.queryAllCourseByCampusId(course);
    }


}
